// pages/map/map.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    longitude: 120.382833,
    latitude: 30.31652,
    markers: [
      {
        id: 0,
        longitude: 120.381833,
        latitude: 30.31652,
        title: '爱心湖',
        iconPath: '../../images/定位.png',
        width: 40,
        height: 40,
        label: {
          content: '爱心湖',
          fontSize: 18,
          textAlign: 'center',
          color: '#ff0000',
          anchorY: 10 //  向下偏移量
        },
        callout: {
          content: '爱心湖',
          fontSize: 18,
          padding: 10,
          borderRadius: 20,
          bgColor: '#fff',
          display: 'ALWAYS'
        }
      },
      {
        id: 1,
        longitude: 120.387307,
        latitude: 30.316969,
        title: '38幢',
        iconPath: '../../images/定位.png',
        width: 40,
        height: 40,
        label: {
          content: '38幢',
          fontSize: 18,
          textAlign: 'center',
          color: '#ff0000',
          anchorY: 10 //  向下偏移量
        },
        callout: {
          content: '爱心湖',
          fontSize: 18,
          padding: 10,
          borderRadius: 20,
          bgColor: '#fff',
          display: 'BYCLICK'
        }
      }
    ],
    polygons: [
      {
        points: [
          { longitude: 120.378957, latitude: 30.31671 },
          { longitude: 120.379601, latitude: 30.318562 },
          { longitude: 120.389085, latitude: 30.318525 },
          { longitude: 120.38902, latitude: 30.31395 },
          { longitude: 120.382798, latitude: 30.313932 }
        ],
        fillColor: '#31acfe'
      }
    ],
    currentLocation: {},
    mapContext: null
  },

  onReady() {
    let obj = { oooo: 100 }
    this.setData({
      mapContext: wx.createMapContext('map', obj)
    })
  },

  handleMarkerTap(e) {
    const id = e.detail.markerId

    const obj = {
      0: () => {
        console.log('--校园爱心湖')
      },
      1: () => {
        console.log('--38幢宿舍')
      }
    }

    obj[id]()
  },

  handleChooseAddress(e) {
    wx.chooseAddress({
      success: (res) => {
        console.log(res)
      }
    })
  },

  handleGetLocation(e) {
    wx.getLocation({
      success: (res) => {
        console.log('getLocation', res)
        this.setData({
          currentLocation: res
        })
      }
    })
  },

  handleChooseLocation() {
    wx.chooseLocation({
      success: (res) => {
        console.log('chooseLocation', res)
      }
    })
  },

  handleOpenLocaction() {
    wx.openLocation({
      latitude: 30.221378,
      longitude: 120.121431
    })
  }
})
